// 引入web3.js库
let Web3 = require("web3")

// 创建web3.js实例，地址对应的是Gannache以太坊测试网
var web3 = new Web3(new Web3.providers.HttpProvider("HTTP://127.0.0.1:7545"))
// 获取ABI接口文件
var contractAbi = JSON.parse('[{"constant":true,"inputs":[],"name":"getNum","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_num","type":"uint256"}],"name":"setNum","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]');
// 创建智能合约对象
var simpleContract = new web3.eth.Contract(contractAbi);
// 获取合约文件数据(16进制 在前面加“0x”)
var simpleContractData = "0x608060405234801561001057600080fd5b5060bf8061001f6000396000f30060806040526004361060485763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166367e0badb8114604d578063cd16ecbf146071575b600080fd5b348015605857600080fd5b50605f6088565b60408051918252519081900360200190f35b348015607c57600080fd5b506086600435608e565b005b60005490565b6000555600a165627a7a72305820196e16e64d69bfdf2e2ac2eed01a3aa53c2425aefab1dbe3b6959f7ac6a295450029"

// 部署合约
simpleContract.deploy({
    data:simpleContractData
}).send({//合约数据
    from:'0xdc913Dc03d9Eb7AEc929B1389C88fa3BCd4D3CeF',//部署合约的外部账户
    gas:1500000,
    gasPrice:'1000000'
},function(err,result){
    console.log(result);//回调函数：打印返回交易结果即hash地址（如果err为空，则result有内容，如果err有内容则交易失败）
})